<?php
    require_once('auth/auth.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Welcome!</title>

<?php
	include('head.php');
?>

</head>


<body>
	<?php 
		$header_title = 'Welcome ' . $_SESSION['SESS_USER_FNAME'] . ' ' . $_SESSION['SESS_USER_LNAME'] . '!';
		include('header.php'); 
		include('menubar.php');
	?>

	<form class="summary">
		<?php

		$userid = $_SESSION['SESS_USER_ID'];
		if(isset($_GET['id']) && is_numeric($_GET['id'])) {
			$expid = $_GET['id'];
		} else {
			die("Chico malo!");
		}

		//Include database connection details
		include('db/config-exp.php');
		$view_path = 0;

		//Connect to mysql server
		$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
		if($link) { 
			$db = mysql_select_db(DB_DATABASE);
			if($db) {
				$qry="Select RESULTATS from EXPERIMENTS WHERE USUARI=" . $userid . " AND IDEXPERIMENT=" . $expid . ";";
 
			       $result=mysql_query($qry);

		        if($result) {
				  if(mysql_num_rows($result) >= 1) {
				 	$row =mysql_fetch_array($result);
					$path= $row['RESULTATS'];
					//abrimos el directorio
					$dir = opendir($path);

					//Mostramos las informaciones
					while ($elemento = readdir($dir))
					{
   						echo $elemento."<br>";
						//Abrimos el archivo en modo lectura
						$fp = fopen($path . "/" . $elemento,"r");
						//Leemos linea por linea el contenido del archivo
	 					while ($linea= fgets($fp,1024))	
	   					{
						  echo $linea;
						  echo "<br>";
						}
						echo "<br>";
					}

					//Cerramos el directorio	
					closedir($dir);
					
		}}}}

		if($row== 0) die("Malo, malisimo!");
		?>
	</form>
</body>
</html>
